package com.xindong.paking.controller;

import com.xindong.paking.dtos.CouponDTO;
import com.xindong.paking.dtos.UserCouponDTO;
import com.xindong.paking.entity.Coupon;
import com.xindong.paking.entity.UserCoupon;
import com.xindong.paking.service.CouponService;
import com.xindong.paking.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/parking/coupon")
@Api(tags = "优惠券管理模块")
public class CouponController {


    @Autowired
    private CouponService couponService;

    @PostMapping("queryByConForPage")
    @ApiOperation("根据条件查询优惠券信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id"),
            @ApiImplicitParam(name = "couponName", value = "优惠券名称"),
            @ApiImplicitParam(name = "couponValue", value = "优惠券价值，查询小于等于"),
            @ApiImplicitParam(name = "couponType", value = "优惠券类型：1、通用。2、满减券。3、折扣券"),
            @ApiImplicitParam(name = "couponNum", value = "优惠券数量，剩余数量，查询小于等于"),
            @ApiImplicitParam(name = "couponDiscount", value = "折扣：如0.5"),
            @ApiImplicitParam(name = "couponDes", value = "优惠券描述"),
            @ApiImplicitParam(name = "expirationTime", value = "过期时间，查询小于等于"),
            @ApiImplicitParam(name = "StartTime", value = "发放时间,查询大于等于"),
            @ApiImplicitParam(name = "status", value = "状态：1、生效，2、失效，3、已结束"),
            @ApiImplicitParam(name = "pageCount", value = "页码,默认为第一页"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数,默认每页10条")
    })
    public Result queryByConForPage(@RequestBody CouponDTO dto) {
        return couponService.queryByConForPage(dto);
    }



    @GetMapping("queryDetailById")
    @ApiOperation("根据id查询优惠券详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "couponId", value = "主键id")
    })
    public Result queryDetailById(@RequestParam("couponId") Integer couponId){
        return couponService.queryDetailById(couponId);
    }


    @PostMapping("deleteById")
    @ApiOperation("根据id删除优惠券信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "couponId", value = "主键id")
    })
    public Result deleteById(@RequestParam("couponId") Integer couponId){
        return couponService.deleteById(couponId);
    }


    @PostMapping("insertCoupon")
    @ApiOperation("添加优惠券信息")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "主键id"),
            @ApiImplicitParam(name = "couponName", value = "优惠券名称"),
            @ApiImplicitParam(name = "couponValue", value = "优惠券价值"),
            @ApiImplicitParam(name = "couponType", value = "优惠券类型：1、通用。2、满减券。3、折扣券"),
            @ApiImplicitParam(name = "couponNum", value = "优惠券数量，剩余数量"),
            @ApiImplicitParam(name = "withAmount", value = "满减券，满多少"),
            @ApiImplicitParam(name = "couponDiscount", value = "折扣：如0.5"),
            @ApiImplicitParam(name = "couponDes", value = "优惠券描述"),
            @ApiImplicitParam(name = "expirationTime", value = "过期时间"),
            @ApiImplicitParam(name = "StartTime", value = "发放时间"),
            @ApiImplicitParam(name = "status", value = "状态：1、生效，2、失效，3、已结束")
    })
    public Result insertCoupon(@RequestBody Coupon dto) {
        return couponService.insertCoupon(dto);
    }


    @PostMapping("UpdateCoupon")
    @ApiOperation("更新优惠券信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id"),
            @ApiImplicitParam(name = "couponName", value = "优惠券名称"),
            @ApiImplicitParam(name = "couponValue", value = "优惠券价值"),
            @ApiImplicitParam(name = "couponType", value = "优惠券类型：1、通用。2、满减券。3、折扣券"),
            @ApiImplicitParam(name = "couponNum", value = "优惠券数量，剩余数量"),
            @ApiImplicitParam(name = "withAmount", value = "满减券，满多少"),
            @ApiImplicitParam(name = "couponDiscount", value = "折扣：如0.5"),
            @ApiImplicitParam(name = "couponDes", value = "优惠券描述"),
            @ApiImplicitParam(name = "expirationTime", value = "过期时间"),
            @ApiImplicitParam(name = "StartTime", value = "发放时间"),
            @ApiImplicitParam(name = "status", value = "状态：1、生效，2、失效，3、已结束")
    })
    public Result UpdateCoupon(@RequestBody Coupon dto) {
        return couponService.UpdateCoupon(dto);
    }
    /**
     * 发放优惠券
     * @param dto
     * @return
     */
    @PostMapping("provideCoupon")
    @ApiOperation("发放优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "couponId", value = "优惠券id")

    })
    public Result provideCoupon(@RequestBody UserCouponDTO dto) {
        return couponService.provideCoupon(dto);
    }

    /**
     * 领取优惠券
     * @param dto
     * @return
     */
    @PostMapping("drawCoupon")
    @ApiOperation("领取优惠券")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id"),
            @ApiImplicitParam(name = "couponId", value = "优惠券id")

    })
    public Result drawCoupon(@RequestBody UserCoupon dto) {
        return couponService.drawCoupon(dto);
    }

}
